<template>
    <div class="xgl-edit">
<el-form ref="form" :model="form" label-width="80px" :rules="rules">
  <el-form-item label="系名称" prop="name">
    <el-input v-model="form.name"></el-input>
  </el-form-item>
  <el-form-item label="学号" prop="number">
    <el-input v-model="form.number"></el-input>
  </el-form-item>
  <el-form-item label="所属班级" prop="classId">
     <el-select filterable v-model="form.classId" placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input v-model="form.password"></el-input>
  </el-form-item>
  <el-form-item label="邮箱" prop="email">
    <el-input v-model="form.email"></el-input>
  </el-form-item>
  <el-form-item label="生日" prop="date">
   <el-date-picker
      v-model="form.birthday "
      type="date"
      placeholder="选择日期">
    </el-date-picker>
  </el-form-item>
  <el-form-item label="性别" prop="sex">
     <el-radio v-model="form.sex" label="1">男</el-radio>
  <el-radio v-model="form.sex" label="0">女</el-radio>
  </el-form-item>
</el-form>
    </div>
</template>
<script>
import {xsglDetail,xsglEdit,departmentAll} from '@/api/xsgl'
export default{
    //获取父传子
    props:["id"],
    data(){
        return{
            form:{
                name:"",
                id:"",
                grade:"",
                classId:"",
                password:"",
                email:"",
                date:""
            },
            rules:{
               name: [
                {required: true, message: '请输入系名称', trigger: 'blur'}
            ],
            grade: [
                    { required: true, message: '请输入专业名称', trigger: 'blur' },
                ],
                classId: [
                    { required: true, message: '请选择系名称', trigger: 'blur' },
                ],
            },
            options:[{

            }]
        }
    },
    methods:{
        onSubmit(cb){
            this.$refs["form"].validate(flag=>{
                if(flag){
                    console.log("参数",this.form);
                    xsglEdit(this.form).then(res =>{
                        cb(res)
                    })
                }
            })
        },
        getDetail(){
            if(this.id){
               xsglDetail(this.id).then(res=>{
                console.log(res);
                if(res.code==0){
                    this.form=res.data
                }        
            }) 
            }
            
        },
        //获取系列表
      getList(){
        departmentAll().then(res=>{
          console.log(res);
          if(res.code===0){
            this.options=res.data
          }
        })
      }
    },
    mounted(){
        this.getDetail()
        this.getList()    
    }
}
</script>